package com.server.modules.sys.utils;

import com.server.modules.sys.entity.customer.impt.CustomerImport;
import com.server.modules.sys.entity.material.MaterialUpload;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/12.
 */
public class CollectionGroupUtils {
    public static   List<List<CustomerImport>> groupListByQuantity(List<CustomerImport> list, int quantity) {
        if (list == null || list.size() == 0) {
            return null;
        }

        if (quantity <= 0) {
            new IllegalArgumentException("Wrong quantity.");
        }
        List<List<CustomerImport>> wrapList = new ArrayList();
        int count = 0;
        while (count < list.size()) {
            wrapList.add(list.subList(count, (count + quantity) > list.size() ? list.size() : count + quantity));
            count += quantity;
        }
        return wrapList;
    }
    public static   List<List<MaterialUpload>> groupMaterialUploadListByQuantity(List<MaterialUpload> list, int quantity) {
        if (list == null || list.size() == 0) {
            return new ArrayList<List<MaterialUpload>>();
        }

        if (quantity <= 0) {
            new IllegalArgumentException("Wrong quantity.");
        }
        List<List<MaterialUpload>> wrapList = new ArrayList();
        int count = 0;
        while (count < list.size()) {
            wrapList.add(list.subList(count, (count + quantity) > list.size() ? list.size() : count + quantity));
            count += quantity;
        }
        return wrapList;
    }
}
